package widgets

import (
	"fyne.io/fyne/v2/widget"
	"github.com/y2h/fyne_poem/util"
)

func Frmtblfield() *widget.Form {
	Index := widget.NewFormItem("Index", widget.NewEntry())
	Name := widget.NewFormItem("Name", widget.NewEntry())
	Type := widget.NewFormItem("Type",
		widget.NewSelect(util.SqliteDataType, nil))
	Null := widget.NewFormItem("Null", widget.NewCheck("", nil))
	Key := widget.NewFormItem("Key", widget.NewEntry())
	Default := widget.NewFormItem("Default", widget.NewEntry())
	Extra := widget.NewFormItem("Extra", widget.NewMultiLineEntry())
	Comment := widget.NewFormItem("Comment", widget.NewMultiLineEntry())
	frm := widget.NewForm(
		Index,Name, Type, Null, Key, Default, Extra, Comment, 
	)
	frm.OnSubmit = func() {}
	return frm
}

/* func form(tbl string) *widget.Form {
	fds, _ := newDb.TableFields(newDb.GetCtx(), tbl)
	header := GetFields(newDb, tbl)
	ty0 := reflect.TypeOf(*fds[header[0]])
	numfd := ty0.NumField()
	frm := widget.NewForm()
	d := gmap.New()
	for i := 0; i < numfd; i++ {
		fieldname := ty0.Field(i).Name
		switch ty0.Field(i).Type.String() {
		case "bool":
			d.Set(fieldname, widget.NewCheck(fieldname, nil))
			frm.Append(fieldname, d.Get(fieldname).(*widget.Check))
		default:
			d.Set(fieldname, widget.NewEntry())
			frm.Append(fieldname, d.Get(fieldname).(*widget.Entry))
		}
	}

	frm.Append("", widget.NewButton("Submit", func() {
		// dd := gmap.New()
		// d.Iterator(func(k, v interface{}) bool {
		// 	dd.Set(k, strings.TrimSpace(v.(*widget.Entry).Text))
		// 	return true
		// })
		// _, err := newDb.Model(thisTbl).Insert(dd)

		// if err != nil {
		// 	msg.SetText("insert err " + err.Error())
		// 	return
		// }
		// rs, _ = newDb.Model(thisTbl).OrderDesc(header[0]).Limit(20).All()
		// lst1.Refresh()
	}))

	return frm
} */
